package com.ssm.hj.controller;

import com.github.pagehelper.PageInfo;
import com.ssm.hj.page.Page;
import com.ssm.hj.search.MenuSearch;
import com.ssm.hj.service.MenuService;
import com.ssm.hj.view.MenuView;
import com.ssm.pojo.Menu;
import com.ssm.pojo.User;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
public class MenuController {
    @Resource
    private MenuService menuService;
    //根据用户查询角色具有的菜单
    @RequestMapping("/hj/queryUserById")
    public List<MenuView> queryUserById(HttpServletRequest request) throws Exception {
        User user =(User)request.getSession().getAttribute("user");
        return this.menuService.queryUserByIdService(user.getId());
    }
    //阿杰 查询子级菜单
    @RequestMapping("/hj/queryMenuChildAll")
    public PageInfo<Menu> queryMenuChildAll(@RequestBody Page<MenuSearch> page) throws Exception {
        return this.menuService.queryMenuChildAllService(page);
    }
    //阿杰 查询父级菜单
    @RequestMapping("/hj/queryMenuParentAll")
    public List<Menu> queryMenuParentAll() throws Exception {
        return this.menuService.queryMenuParentAll();
    }
    //阿杰 修改菜单状态
    @RequestMapping("/hj/updateMenuState")
    public int updateMenuState(int id,int state) throws Exception {
        return this.menuService.updateMenuStateService(id,state);
    }
}
